package com.LJH.WebTask4.mybatis.mapper;

import com.LJH.WebTask4.mybatis.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BookMapper {

    @Select("select * from bookList")
    List<Book> selectAll();

    @Select("select * from bookList where index = #{index}")
    Book selectById(int index);

    @Insert("insert into bookList(name, author, press, publicDate, surplus) " +
            "values (#{name}, #{author}, #{press}, #{publicDate}, #{surplus})")
    @Options(useGeneratedKeys = true, keyProperty = "index")
    void insert(Book book);

    @Delete("delete from bookList where index = #{index}")
    void deleteById(int index);

    @Update("update bookList set (name, author, press, publicDate, surplus) =" +
            "(#{name}, #{author}, #{press}, #{publicDate}, #{surplus})" +
            "where index = #{index}")
    void update(Book book);
}
